﻿/*
 * Tick.h
 *
 */
#ifndef __GDK_TICK_H__
#define __GDK_TICK_H__

#include <gdk/core/Types.h>
#include <gdk/core/Task.h>
#include <gdk/core/Callback.h>
#include <list>


namespace gdk
{


	class GDK_CORE_EXPORT Tick : public Task
	{
		DECLARE_CLASS_HANDLE(Tick)
		DECLARE_CLASS_INSTANCE(Tick)

	public:
		typedef CallbackHandler<void, uint32_t> TickHandler;
		typedef std::list<TickHandler>          TickHandlerList;
		typedef TickHandlerList::iterator       TickHandlerList_Iterator;
		typedef TickHandlerList::const_iterator TickHandlerList_ConstIterator;

	private:
		TickHandlerList		_tickHandlerList;

	protected:
		__INLINE__ Tick(void)
		{}

	public:
		virtual void onTick(uint32_t timeSinceLastTick);

	public:
		bool addTickHandler(const TickHandler &o);
		void removeTickHandler(const TickHandler &o);
		void clearAllTickHandler(void);
		//----------------------------------------------------
		bool addTickHandler(void(*func)(uint32_t))
		{
			return addTickHandler(TickHandler(func));
		}
		template<typename TyClass>
		bool addTickHandler(const SharedPtr<TyClass> &obj, void(TyClass::*func)(uint32_t))
		{
			return addTickHandler(TickHandler(obj, func));
		}
		template<typename TyClass>
		bool addTickHandler(TyClass *obj, void(TyClass::*func)(uint32_t))
		{
			return addTickHandler(TickHandler(obj, func));
		}
		template<typename TyClass>
		bool addTickHandler(TyClass &obj, void(TyClass::*func)(uint32_t))
		{
			return addTickHandler(TickHandler(obj, func));
		}
		template<typename TyClass>
		bool addTickHandler(const Unknown::Handle_T<TyClass> &obj, void(TyClass::*func)(uint32_t))
		{
			return addTickHandler(TickHandler(obj, func));
		}
		//----------------------------------------------------
		void removeTickHandler(void(*func)(uint32_t))
		{
			return removeTickHandler(TickHandler(func));
		}
		template<typename TyClass>
		void removeTickHandler(const SharedPtr<TyClass> &obj, void(TyClass::*func)(uint32_t))
		{
			return removeTickHandler(TickHandler(obj, func));
		}
		template<typename TyClass>
		void removeTickHandler(TyClass *obj, void(TyClass::*func)(uint32_t))
		{
			return removeTickHandler(TickHandler(obj, func));
		}
		template<typename TyClass>
		void removeTickHandler(TyClass &obj, void(TyClass::*func)(uint32_t))
		{
			return removeTickHandler(TickHandler(obj, func));
		}
		template<typename TyClass>
		void removeTickHandler(const Unknown::Handle_T<TyClass> &obj, void(TyClass::*func)(uint32_t))
		{
			return removeTickHandler(TickHandler(obj, func));
		}
		//----------------------------------------------------
	};






}//namespace gdk


#endif /*__GDK_TIMER_H__*/
